#include "typedefs.h"

#define PCI_CONFIG_ADDR 0xCF8
#define PCI_CONFIG_DATA 0xCFC
#define PCI_CONFIG_ENABLE (1 << 31)
#define PCI_IF_PCI_FUNC_ID 0xB100
#define PCI_IF_BIOS_PRESENT 0x0001
#define PCI_SPACE_DEVICEID 0x00
#define PCI_SPACE_COMMAND 0x04
#define PCI_SPACE_STATUS 0x04
#define PCI_SPACE_CLASSREV 0x08
#define PCI_SPACE_TYPE 0x0C
#define PCI_BASE_ADDRESS_0      0x10    /* 32 bits */
#define PCI_BASE_ADDRESS_1      0x14    /* 32 bits */
#define PCI_BASE_ADDRESS_2      0x18    /* 32 bits */
#define PCI_BASE_ADDRESS_3      0x1c    /* 32 bits */
#define PCI_BASE_ADDRESS_4      0x20    /* 32 bits */
#define PCI_BASE_ADDRESS_5      0x24    /* 32 bits */
#define PCI_SPACE_CARDBUS 0x28
#define PCI_SPACE_SUBSYS 0x2C
#define PCI_SPACE_EXPROM 0x30
#define PCI_SPACE_INT 0x3C

#define PCI_BIOS32_START 0xE0000
#define PCI_BIOS32_END 0xFFFFF
#define PCI_BIOS32_SIGNATURE "_32_"
#define PCI_BIOS_SERVICE_ID 0x49435024
#define PCI_IF_PCI_FUNC_ID 0xB100
#define PCI_IF_BIOS_PRESENT 0x0001
#define PCI_IF_SIGNATURE "PCI "

#define ERR_PCI_BIOS32_NOTFOUND 1
#define ERR_PCI_BIOS32_NOTIMPL 2
#define ERR_PCI_BIOS_NOTIMPL 3
#define ERR_PCI_BAD_MECH 4
#define ERR_PCI_DEV_INVALID 5

#define	PCI_BASE_ADDRESS_IO_MASK       (~0x03)
#define	PCI_BASE_ADDRESS_SPACE_IO	0x01

#define PCI_COMMAND_IO			0x1	/* Enable response in I/O space */
#define PCI_COMMAND_MEM			0x2	/* Enable response in mem space */
#define PCI_COMMAND_MASTER		0x4	/* Enable bus mastering */
#define PCI_LATENCY_TIMER		0x0d	/* 8 bits */
#define PCI_COMMAND_SPECIAL		0x8	/* Enable response to special cycles */
#define PCI_COMMAND_INVALIDATE		0x10	/* Use memory write and invalidate */
#define PIC1 0x20
#define PIC2 0xA0
#define ICW1 0x11
#define ICW4 0x01
#define PCI_CONFIG_ADDR 0xCF8
#define PCI_CONFIG_DATA 0xCFC
#define PCI_CONFIG_ENABLE (1 << 31)
#define PCI_IF_PCI_FUNC_ID 0xB100
#define PCI_IF_BIOS_PRESENT 0x0001

void init_8259s();
word pci_scan_device(word, word, word);
word pci_scan_vendor(word, word, word);
unsigned long pci_scan_ioentry(dword, dword, dword);
unsigned int scan_pci_buses(void);
void adjust_pci_device(dword bus, dword dev, dword fun);
unsigned int pci_bios_present();
unsigned int det_pres_bios32_service_directory(void);
unsigned int det_pci_bios_in_SD();
extern unsigned long pci_entry_point;
